package com.itheima.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAspect {
    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    public void pt(){}
    @Around("pt()")
    public Object totalTime(ProceedingJoinPoint pjp) throws Throwable {
        //原有代码前的逻辑
        long l = System.currentTimeMillis();
        Object proceed = pjp.proceed();
        long l2 = System.currentTimeMillis();
        long time = l2-l;
        System.out.println(pjp.getSignature().getDeclaringTypeName()+"类中的"+pjp.getSignature().getName()+"方法执行耗时"+time+"毫秒===================================");
    return proceed;
    }
}
